import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class TcpClientSocket {
    private Socket socket = null;
    public TcpClientSocket(String address,int  port) throws IOException {
        socket = new Socket(address,port);
    }
    public void start() {
        System.out.println("'客户端启动");
        try(InputStream inputStream = socket.getInputStream();
            OutputStream outputStream = socket.getOutputStream()){
            Scanner scanner = new Scanner(System.in);
            Scanner Rescanner = new Scanner(inputStream);
            while (true) {
                String request = scanner.next();
                request += "/n";
                outputStream.write(request.getBytes());
                if(!Rescanner.hasNext()) {
                    break;
                }
                String response = Rescanner.next();
                System.out.println(response);
            }
        }catch (IOException e) {
            e.printStackTrace();
        }
    }
}
